<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<%@ include file="../common.inc" %>    
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Insert title here</title>
<link href="./css/style1.css" rel="stylesheet" type="text/css" />
<script type="text/javascript" src="./js/form.js"></script>
<script type="text/javascript" language="javascript">
<!--
	function checkForm(){
		var wObjs = document.getElementsByName("warningItem");
		var sign = 0;
		for(var i = 0; i < wObjs.length; i++){
			if(wObjs[i].checked){
				var uObj = document.getElementById("warningItem"+wObjs[i].value);
				if(uObj.value == "" || uObj.value == "0"){
					var info = "";
					if(wObjs[i].value == '1'){
						info = "员工生日";
					}else if(wObjs[i].value == '2'){
						info = "审批流程提醒";
					}else if(wObjs[i].value == '3'){
						info = "客户生日";
					}else if(wObjs[i].value == '4'){
						info = "日程管理提醒";
					}else if(wObjs[i].value == '5'){
						info = "拜访提醒";
					}else if(wObjs[i].value == '6'){
						info = "公海规则提醒";
					}else if(wObjs[i].value == '7'){
						info = "合同到期提醒";
					}
					alert(info + " 预警项没有选择预警对象！");
					return false;
				}
				sign = sign + 1;
			}
		}
		if(sign <= 0){
			alert("请选择预警项！");
			return false;
		}
		
		var wayObjs = document.getElementsByName("warningWay");
		var sign2 = 0;
		for(var i = 0; i < wayObjs.length; i++){
			if(wayObjs[i].checked){
				sign2 = sign2 + 1;
			}
		}
		if(sign2 <= 0){
			alert("请选择预警方式！");
			return false;
		}
		return true;
	}

	function earlyWarningObject(){
		window.location.href = "earlyWarningObject.html";
		window.location.target = "main";
	}
	
	function addSaleRecord(){
		window.location.href = "addSaleRecord.html";
		window.location.target = "main";
	}
	
	function updateSaleRecord(){
		window.location.href = "updateRecord.html";
		window.location.target = "main";
	}
	
	function earlyWarningObjectDialog(warningItem){
		var warningObjects = document.getElementById("warningItem"+warningItem).value;
		var url = "./warningManage.do?action=warningObject&warningItem="+warningItem+"&warningItem"+warningItem+"="+warningObjects;
		//var url = "./warningManage.do?action=warningObject&warningItem="+warningItem;
		var dlgParam = "dialogHeight:360px;dialogWidth:450px;dialogTop:300px;dialogLeft:400px;status:no;help:no;scrollbars:yes;";
		var rt = window.showModalDialog(url,"",dlgParam);
		if(rt != undefined){			
			//根据从子窗口得到的值，从中提取预警项号、预警对象ids
			var warningItem = "";
			var userIds = "";
			var str = rt.split("##");
			if(str[0] != "" && str[1] != ""){
				warningItem = str[0];
				userIds = str[1];
			}
			document.getElementById("warningItem"+warningItem).value = userIds;										
		}
	}
	
	function checkedWarningItem(obj,warningItem){
		if(obj.checked){
			earlyWarningObjectDialog(warningItem);
		}
	}
	
	function save(){
		if(checkForm()){
			document.warningManageForm.action = "./warningManage.do?action=startWarning";
			document.warningManageForm.target = "main";
			document.warningManageForm.submit();
		}
	}
	
	function stopWarningPlan(){
		document.warningManageForm.action = "./warningManage.do?action=stopWarningPlan";
		document.warningManageForm.target = "main";
		document.warningManageForm.submit();
	}
	
	function initPage(){
		if("<c:out value='${result}'/>" == 1){
			alert("启用成功！");
		}else if("<c:out value='${result}'/>" == 2){
			alert("停用成功！");
		}
	}
-->
</script>
</head>
<body onload="initPage()">
<form name="warningManageForm" action="" method="post">
	<table class="table_frame">
		<tr>
			<td>
				<table class="table_title1">
					<tr>
						<td class="title_lab" colspan="2">预警计划</td>
					</tr>
					<tr>
						<td valign="bottom" class="a_tools" style="padding-left: 3px;">
							<a href="javascript:save();" title="启用" hidefocus="true">启用</a>
							<a class="closestage" href="javascript:stopWarningPlan();" title="停用" hidefocus="true">停用</a>
						</td>
						<td></td>
					</tr>
					<tr><td height="2"></td></tr>
				</table>
			</td>
		</tr>
		<tr>
			<td>
				<table class="table_title2">
					<c:if test="${warningWay['isWay'] == 'false'}">
					<tr>
						<td height="30" align="center" style="font-weight: bold;font-size: 14px;color: red;">暂未启用预警计划！</td>
					</tr>
					</c:if>
					<tr>
						<td class="title_lab">预警项目</td>
					</tr>
					<tr>
						<td>
							<table class="table">
								<tr>
									<td valign="top">
										<table class="table_style">
											<tr>
												<td class="title" width="30">选择</td>
												<td class="title">项目</td>
												<td class="title">预警源</td>
												<td class="title" width="12%">操作</td>
											</tr>
											<!-- 
											<tr>
												<td>
													<input id="warningItem" name="warningItem" type="checkbox" value="1" 
														onclick="checkedWarningItem(this,'1')" <c:if test='${warningPlan["w1"].status == 1}'>checked</c:if> />
												</td>
												<td>员工生日</td>
												<td>内部预警</td>
												<td>
													<img class="btn_img" src="./images/a_object.gif" onclick="earlyWarningObjectDialog('1')" title="预警对象">
													<input id="warningItem1" name="warningItem1" type="hidden" value="${warningPlan['w1'].MValue}"/>
												</td>
											</tr>
											 -->
											<tr>
												<td>
													<input id="warningItem" name="warningItem" type="checkbox" value="2" 
														onclick="checkedWarningItem(this,'2')" <c:if test='${warningPlan["w2"].status == 1}'>checked</c:if> />
												</td>
												<td>审批流程提醒</td>
												<td>内部预警</td>
												<td>
													<img class="btn_img" src="./images/a_object.gif" onclick="earlyWarningObjectDialog('2')" title="预警对象">
													<input id="warningItem2" name="warningItem2" type="hidden" value="${warningPlan['w2'].MValue}"/>
												</td>
											</tr>
											<!-- 
											<tr>
												<td>
													<input id="warningItem" name="warningItem" type="checkbox" value="3" 
														onclick="checkedWarningItem(this,'3')" <c:if test='${warningPlan["w3"].status == 1}'>checked</c:if> />
												</td>
												<td>客户生日</td>
												<td>销售预警</td>
												<td>
													<img class="btn_img" src="./images/a_object.gif" onclick="earlyWarningObjectDialog('3')" title="预警对象">
													<input id="warningItem3" name="warningItem3" type="hidden" value="${warningPlan['w3'].MValue}"/>
												</td>
											</tr>
											 -->
											<tr>
												<td>
													<input id="warningItem" name="warningItem" type="checkbox" value="4" 
														onclick="checkedWarningItem(this,'4')" <c:if test='${warningPlan["w4"].status == 1}'>checked</c:if> />
												</td>
												<td>日程管理提醒</td>
												<td>销售预警</td>
												<td>
													<img class="btn_img" src="./images/a_object.gif" onclick="earlyWarningObjectDialog('4')" title="预警对象">
													<input id="warningItem4" name="warningItem4" type="hidden" value="${warningPlan['w4'].MValue}"/>
												</td>
											</tr>
											<!-- 
											<tr>
												<td>
													<input id="warningItem" name="warningItem" type="checkbox" value="5" 
														onclick="checkedWarningItem(this,'5')" <c:if test='${warningPlan["w5"].status == 1}'>checked</c:if> />
												</td>
												<td>拜访提醒</td>
												<td>销售预警</td>
												<td>
													<img class="btn_img" src="./images/a_object.gif" onclick="earlyWarningObjectDialog('5')" title="预警对象">
													<input id="warningItem5" name="warningItem5" type="hidden" value="${warningPlan['w5'].MValue}"/>
												</td>
											</tr>
											 -->
											<tr>
												<td>
													<input id="warningItem" name="warningItem" type="checkbox" value="6" 
														onclick="checkedWarningItem(this,'6')" <c:if test='${warningPlan["w6"].status == 1}'>checked</c:if> />
												</td>
												<td>公海规则提醒</td>
												<td>销售预警</td>
												<td>
													<img class="btn_img" src="./images/a_object.gif" onclick="earlyWarningObjectDialog('6')" title="预警对象">
													<input id="warningItem6" name="warningItem6" type="hidden" value="${warningPlan['w6'].MValue}"/>
												</td>
											</tr>
											<!-- 
											<tr>
												<td>
													<input id="warningItem" name="warningItem" type="checkbox" value="7" 
														onclick="checkedWarningItem(this,'7')" <c:if test='${warningPlan["w7"].status == 1}'>checked</c:if> />
												</td>
												<td>合同到期提醒</td>
												<td>合同预警</td>
												<td>
													<img class="btn_img" src="./images/a_object.gif" onclick="earlyWarningObjectDialog('7')" title="预警对象">
													<input id="warningItem7" name="warningItem7" type="hidden" value="${warningPlan['w7'].MValue}"/>
												</td>
											</tr>
											
											<tr>
												<td><input type="checkbox"/></td>
												<td>服务提醒</td>
												<td>服务预警</td>
												<td><img class="btn_img" src="../../images/a_object.gif" onclick="earlyWarningObjectDialog('8')" title="预警对象"></td>
											</tr>
											<tr>
												<td><input type="checkbox"/></td>
												<td>服务超期提醒</td>
												<td>服务预警</td>
												<td><img class="btn_img" src="../../images/a_object.gif" onclick="earlyWarningObjectDialog('9')" title="预警对象"></td>
											</tr>
											 -->
										</table><br><br>
									</td>
								</tr>
								<tr>
									<td class="title_lab">预警方式 </td>
								</tr>
								<tr>
									<td>
										<table class="table_style">
											<tr>
												<td class="title" width="30">选择</td>
												<td class="title" width="20%">方式</td>
												<td class="title">说明</td>
											</tr>
											<tr>
												<td>
													<input id="warningWay" name="warningWay" type="checkbox" 
														value="1" <c:if test='${warningWay["way1"].status == 1}'>checked</c:if> />
												</td>
												<td>工作门户</td>
												<td align="left">以显示在首页面方式提醒</td>
											</tr>
											<tr>
												<td>
													<input id="warningWay" name="warningWay" type="checkbox" 
														value="2" <c:if test='${warningWay["way2"].status == 1}'>checked</c:if> />
												</td>
												<td>内部信息</td>
												<td align="left">以内部信箱方式提醒</td>
											</tr>
											<tr>
												<td>
													<input id="warningWay" name="warningWay" type="checkbox" 
														value="3" <c:if test='${warningWay["way3"].status == 1}'>checked</c:if> />
												</td>
												<td>电子邮件</td>
												<td align="left">以电子邮件方式提醒(注：如需要邮件提醒，服务器必须能够上网。)</td>
											</tr>
										</table>
									</td>
								</tr>
							</table>
						</td>
					</tr>
				</table>
			</td>
		</tr>
	</table>
</form>
</body>
</html>